import ACCESS_ENUM from "@/access/accessEnum";

interface State {
  loginUser: {
    userName: string;
  };
}

interface Mutations {
  updateUser: (state: State, payload: { userName: string }) => void;
}

import { Commit } from "vuex";
import { UserControllerService } from "../../generated";

// 存储的状态
const state = () => ({
  loginUser: {
    userName: "未登录",
    role: "notLogin",
    userRole: ACCESS_ENUM.NOT_LOGIN,
  },
});

// getters
const getters = {};

// actions,, 异步之后  调用 mutation
const actions = {
  async getLoginUser(
    {
      commit,
    }: {
      commit: (
        mutation: keyof Mutations,
        payload: { userName: string }
      ) => void;
    },
    payload: any
  ) {
    const res = await UserControllerService.getLoginUserUsingGet();

    // if (res.code === 0){}
    // const obj: any = ;
    commit("updateUser", payload);
  },
};

// mutations
const mutations = {
  updateUser(state: State, payload: any) {
    state.loginUser = payload;
  },
};

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations,
};
